window.onload = function () {
    // dom获取
    let username = document.querySelector('[name="username"]')
    let password = document.querySelector('[name="password"]')
    let toLogin = document.querySelector('.tologin')
    let form = document.querySelector('form')

    // 业务处理
    // 登录页跳转
    toLogin.onclick = () => {
        location.href = '/login.html'
    }
    // 注册
    form.onsubmit = () => {
        promiseRequest({
            method: 'post',
            url: '/front/api/user/register',
            data: {
                username: username.value,
                password: password.value
            }
        }).then(res => {
            if (res.error_code === 200) {
                popup.msg(res.msg,()=>{
                    location.href = '/login.html'
                })
            }else{
                popup(res.msg)
            }
        })
        return false
    }


    // 测试区
    // submitBtn.onclick = () => {
    //     console.log(username.value,password.value);

    //     return false
    // }
    // console.log();
}